package top.hmtools.callBacks;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
import top.hmtools.beans.MapperXmlSqlPartGroupBean;

public class SqlPartGroupListCallback    implements      Callback<TreeView<String>, TreeCell<String>> {

    private Callback<TreeView<String>, TreeCell<String>> defaultCallBack;
    private TextField groupId;
    private TextField tf_groupName;
    private TextField tf_factorName;
    private TextArea ta_comment;

    public SqlPartGroupListCallback( Callback<TreeView<String>, TreeCell<String>> defaultCellFactory) {
        this.defaultCallBack = defaultCellFactory;
    }

    public SqlPartGroupListCallback(
            Callback<TreeView<String>, TreeCell<String>> defaultCellFactory,
            TextField groupId, TextField tf_groupName, TextField tf_factorName,
            TextArea ta_comment) {
        this.defaultCallBack = defaultCellFactory;
        this.groupId =groupId;
        this.tf_groupName=tf_groupName;
        this.tf_factorName=tf_factorName;
        this.ta_comment=ta_comment;
    }

    /**
     * 方法说明
     * 输入参数说明
     * 输出参数说明
     */
    @Override
    public TreeCell<String> call(TreeView<String> param) {
        TreeCell<String> result = defaultCallBack.call(param);
        result.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>(){

            @Override
            public void handle(Event event) {
                TreeCell<String> treeCell = (TreeCell<String>) event.getSource();
                TreeItem<String> treeItem = treeCell.getTreeItem();
                if(treeItem ==null){
                	return;
                }
                MapperXmlSqlPartGroupBean userData = (MapperXmlSqlPartGroupBean) treeItem.getGraphic().getUserData();

                groupId.setText(userData.getId()); 
                tf_groupName.setText(userData.getName());
                tf_factorName.setText(userData.getFactor_name());
                ta_comment.setText(userData.getComment());
            }
            
        });
        return result;
    }

}
